package com.lysj.admin.master.auth.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lysj.admin.master.auth.domain.Role;
import com.lysj.admin.master.auth.dto.RoleConditionDTO;
import com.lysj.admin.master.auth.mapper.RoleMapper;
import com.lysj.admin.master.auth.service.RoleService;
import com.lysj.admin.master.common.annotation.Delete;
import com.lysj.admin.master.common.annotation.Save;
import com.lysj.admin.master.common.spring.mpbase.MyController;
import com.lysj.admin.master.common.spring.mpbase.MyService;
import com.lysj.admin.master.common.spring.pagination.PageRequestDTO;
import com.lysj.admin.master.common.web.Resp;
import com.lysj.admin.master.common.web.RespUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Created by zk on 2019-12-05 2:27
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/auth/role")
public class RoleController extends MyController<RoleMapper,Role,PageRequestDTO> {
    @Resource
    private RoleService roleService;

    @Override
    public MyService<RoleMapper, Role> getService() {
        return roleService;
    }

    @Override
    @Save
    public Resp save(Role entity) {
        return super.save(entity);
    }

    @GetMapping("find_by_type")
    public Resp findByType(RoleConditionDTO condition) {
        Page<Role> roles = roleService.roleList(condition);
        return RespUtil.success(roles);
    }

    @PostMapping(value = "/edit_role_perm")
    public Resp editRolePerm(String id, String[] permIds){
        roleService.editRolePerm(id,permIds);
        return RespUtil.success("权限分配成功");
    }

    @Override
    @Delete
    public Resp delete(String[] ids) {
        roleService.deleteRole(ids);
        return RespUtil.success("删除成功");
    }


}
